package com.allwees.bs.c.module.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.allwees.bs.c.module.product.dao.FreeGiftRecordDao;
import com.allwees.bs.c.module.product.entity.FreeGiftRecord;
import com.allwees.bs.c.module.product.service.FreeGiftRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author Daniel
 * @Version 1.0.0
 * @Description
 * @CreateTime 2020/9/11 19:56
 */
@Slf4j
@Service
public class FreeGiftRecordServiceImpl extends ServiceImpl<FreeGiftRecordDao, FreeGiftRecord> implements FreeGiftRecordService {

    @Override
    public boolean applied(String userUuid, String productUuid) {
        if(hasApplied(userUuid)){
            log.info(">>>user has applied free gift,userUuid:{}",userUuid);
            return false;
        }
        FreeGiftRecord freeGiftRecord = new FreeGiftRecord();
        freeGiftRecord.setUserUuid(userUuid);
        freeGiftRecord.setProductUuid(productUuid);
        freeGiftRecord.setCreatedAt(new Date());
        return super.save(freeGiftRecord);
    }

    @Override
    public boolean hasApplied(String userUuid) {
        return super.getById(userUuid) != null;
    }
}
